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 index 9f8aba3af03be425a8a833f3f70bf5fa3b8f35fc..ad307e47ad3747bfb311d7c1033214d40c7c46c7 100644 --- a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/PetDetailsManagedBean.java @@ -24,7 +24,6 @@ import es.uvigo.esei.xcs.service.VaccinationService; import es.uvigo.esei.xcs.service.VaccineService; @Named("petDetails") -//@RequestScoped @ViewScoped public class PetDetailsManagedBean implements Serializable{ private static final long serialVersionUID = 1L; @@ -42,7 +41,7 @@ public class PetDetailsManagedBean implements Serializable{ private Pet pet; private Long selectedVaccineId; - private Date vaccinationDate; // yyyy-MM-dd + private Date vaccinationDate; private List allVaccines; @PostConstruct 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 c7ce056da805c339d1696250e7f0b70b265394ac..f6228c6b630f83d17476f1a601dccfeb0634f69e 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 @@ -22,7 +22,6 @@ import es.uvigo.esei.xcs.domain.entities.Pet; import es.uvigo.esei.xcs.service.PetService; @Named("pet") -//@RequestScoped @ViewScoped public class PetManagedBean implements Serializable{ private static final long serialVersionUID = 1L; @@ -119,14 +118,7 @@ public class PetManagedBean implements Serializable{ this.id = id; } - /*public List getPets() { - List list = this.service.getAll(0, 100); - System.out.println(list); - return list; - }*/ - public String edit(Long petId) { - //throw new RuntimeException("ERROR GRAVE (" + petId + ")"); final Pet pet = this.service.get(petId); this.id = pet.getId(); @@ -134,7 +126,7 @@ public class PetManagedBean implements Serializable{ this.birth = pet.getBirth(); this.animal = pet.getAnimal(); - return null;// this.getViewId(); + return null; } public String cancelEditing() { @@ -159,7 +151,6 @@ public class PetManagedBean implements Serializable{ this.service.update(pet); } else { - //this.service.create(new Pet(name, animal, birth)); this.service.createPet(name, animal, birth); } diff --git a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java index a9acee8f0bd830bc1222dd80bc48ca6854882951..1acd0e6474134014c938b45888932ab4ee4aacca 100644 --- a/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java +++ b/jsf/src/main/java/es/uvigo/esei/xcs/jsf/VaccineManagedBean.java @@ -11,7 +11,6 @@ import es.uvigo.esei.xcs.domain.entities.Vaccine; import es.uvigo.esei.xcs.service.VaccineService; @Named("vaccine") -//@RequestScoped @ViewScoped public class VaccineManagedBean implements Serializable{ private static final long serialVersionUID = 1L; @@ -42,18 +41,27 @@ public class VaccineManagedBean implements Serializable{ vaccines = vaccineService.list(0, 100); } - private Vaccine selectedVaccine; // vacuna que vamos a editar - private String newName; // nuevo nombre para editar + private Vaccine selectedVaccine; + private String newName; - public Vaccine getSelectedVaccine() { return selectedVaccine; } + public Vaccine getSelectedVaccine() { + return selectedVaccine; + } + public void setSelectedVaccine(Vaccine selectedVaccine) { this.selectedVaccine = selectedVaccine; if (selectedVaccine != null) { - this.newName = selectedVaccine.getName(); // precarga el nombre actual + this.newName = selectedVaccine.getName(); } } - public String getNewName() { return newName; } - public void setNewName(String newName) { this.newName = newName; } + + public String getNewName() { + return newName; + } + + public void setNewName(String newName) { + this.newName = newName; + } public void editVaccine() { if (selectedVaccine != null && newName != null && !newName.trim().isEmpty()) { @@ -72,16 +80,49 @@ public class VaccineManagedBean implements Serializable{ periodicType = null; } - // Getters y setters - public List getVaccines() { return vaccines; } - public String getName() { return name; } - public void setName(String name) { this.name = name; } - public String getType() { return type; } - public void setType(String type) { this.type = type; } - public Integer getDoses() { return doses; } - public void setDoses(Integer doses) { this.doses = doses; } - public Integer getPeriode() { return periode; } - public void setPeriode(Integer periode) { this.periode = periode; } - public String getPeriodicType() { return periodicType; } - public void setPeriodicType(String periodicType) { this.periodicType = periodicType; } + + public List getVaccines() { + return vaccines; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Integer getDoses() { + return doses; + } + + public void setDoses(Integer doses) { + this.doses = doses; + } + + public Integer getPeriode() { + return periode; + } + + public void setPeriode(Integer periode) { + this.periode = periode; + } + + public String getPeriodicType() { + return periodicType; + } + + public void setPeriodicType(String periodicType) { + this.periodicType = periodicType; + } + } 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 0fa984157b66544c6be15bf84f551a7cd62c2331..a214546714c8218c2c6245f6aff60d03f95d455b 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 @@ -22,7 +22,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet; import es.uvigo.esei.xcs.service.VetService; @Named("vet") -//@RequestScoped @ViewScoped public class VetManagedBean implements Serializable{ private static final long serialVersionUID = 1L; @@ -93,10 +92,6 @@ public class VetManagedBean implements Serializable{ public List getVets() { return this.service.list(); } - - /*public List getPets() { - return this.service.getPets(0, 100); - }*/ public String getPetNames() { return this.service.getPets(0, 100).stream() diff --git a/jsf/src/main/webapp/index.xhtml b/jsf/src/main/webapp/index.xhtml index 1e31f7bc1e0cfdba263ac34258ffac4e67c6c779..68fe001e4cc5e8feb3e2e3047486146a78990beb 100644 --- a/jsf/src/main/webapp/index.xhtml +++ b/jsf/src/main/webapp/index.xhtml @@ -14,7 +14,6 @@

Welcome!

This is the Pet Store web page, where you can manage your pets. Please, login to continue.
-
diff --git a/rest/src/main/java/es/uvigo/esei/xcs/rest/OwnerResource.java b/rest/src/main/java/es/uvigo/esei/xcs/rest/OwnerResource.java index 63c32ae2f17176af8f281bd2a41545f97a5f7a32..3e5d5f6ae61ae8dba1b520b9d20b99e61ca35837 100644 --- a/rest/src/main/java/es/uvigo/esei/xcs/rest/OwnerResource.java +++ b/rest/src/main/java/es/uvigo/esei/xcs/rest/OwnerResource.java @@ -140,10 +140,9 @@ public class OwnerResource { } - @Path("{login}/pet/{petIdentifierType}/{petIdentifierValue}/vaccination") + @Path("pet/{petIdentifierType}/{petIdentifierValue}/vaccination") @GET public Response listVaccinations( - @PathParam("login") String login, @PathParam("petIdentifierType") IdentifierType petIdentifierType, @PathParam("petIdentifierValue") String petIdentifierValue, @QueryParam("page") int page, @@ -151,7 +150,7 @@ public class OwnerResource { ) { return Response.ok(this.service.getVaccinationsFromOwnPet( - login, + //login, petIdentifierType, petIdentifierValue, page, diff --git a/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccinationResource.java b/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccinationResource.java index 1380454b2d9330d407310de61a9856dee3ca5af5..099efc68fe347cb7b6984de1cf5cf77af2c7162a 100644 --- a/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccinationResource.java +++ b/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccinationResource.java @@ -43,7 +43,7 @@ public class VaccinationResource { public Response createVaccination( @PathParam("petId") Long petId, @PathParam("vaccineId") Long vaccineId, - @QueryParam("date") String textDate // opcional, formato yyyy-MM-dd + @QueryParam("date") String textDate ) { Date date = new Date(); if (textDate != null) { diff --git a/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccineResource.java b/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccineResource.java index 353abb26f479b85580a9302bcfd02eb296b572f7..e38b5511d1b9f46987998a8f978d37bb29eaea66 100644 --- a/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccineResource.java +++ b/rest/src/main/java/es/uvigo/esei/xcs/rest/VaccineResource.java @@ -32,7 +32,6 @@ public class VaccineResource { @POST public Response create(VaccineCreationData vaccineData) { requireNonNull(vaccineData, "vaccineData can't be null"); - //Vaccine vaccine = vaccineService.create(vaccineData.toVaccine()); Vaccine vaccine = vaccineService.create( vaccineData.getName(), vaccineData.getType(), 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 484a44beb5c397569e62e6843f8039486cbc6a78..ade0b5d42d02cc4e8b4240388b652a30226a2bde 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 @@ -100,12 +100,9 @@ public class VetResource { @GET @Path("pets") public Response listPets( - //@PathParam("login") String login, @QueryParam("page") @DefaultValue("0") int page, @QueryParam("pageSize") @DefaultValue("10") int pageSize ) { - //requireNonNull(login, "login can't be null"); - return Response.ok(this.vetService.getPets(page, pageSize)).build(); } @@ -124,10 +121,16 @@ public class VetResource { } - @Path("vaccine") @POST + @Path("vaccine") public Response createVaccine(VaccineCreationData vaccineData) { - Vaccine vaccine = null;//this.vaccineService.create(vaccineData.toVaccine()); + Vaccine vaccine = this.vaccineService.create( + vaccineData.getName(), + vaccineData.getType(), + vaccineData.getDoses(), + vaccineData.getPeriodicType(), + vaccineData.getPeriode() + ); return Response.ok(vaccine).build(); } @@ -155,16 +158,14 @@ public class VetResource { } } - @Path("pets/{petIdentifierType}/{petIdentifierValue}/vaccination") + @Path("pet/{petIdentifierType}/{petIdentifierValue}/vaccination") @GET public Response listVaccinations( - @PathParam("login") String login, @PathParam("petIdentifierType") IdentifierType petIdentifierType, @PathParam("petIdentifierValue") String petIdentifierValue, @QueryParam("page") int page, @QueryParam("pageSize") int pageSize ) { - requireNonNull(login, "login can't be null"); return Response.ok(this.vetService.getVaccinationsFromOwnPet( //login, @@ -175,12 +176,15 @@ public class VetResource { )).build(); } - @Path("pets/{petIdentifierType}/{petIdentifierValue}/vaccination") + @Path("vaccination") @POST public Response registerVaccination( @QueryParam("date") Date date, VaccinationCreationData vaccinationData ) { + if (date == null) { + date = new Date(); + } Vaccination vaccination = this.vaccinationService.create( vaccinationData.getPetId(), vaccinationData.getVaccineId(), @@ -197,16 +201,13 @@ public class VetResource { @POST @Path("/assign/pets/{petId}") public Response assignVetToPet( - //@PathParam("login") String vetLogin, @PathParam("petId") Long petId ) { - //requireNonNull(vetLogin, "vetLogin can't be null"); requireNonNull(petId, "petId can't be null"); try { petService.assignVetToPet(petId); return Response.ok() - //.entity("Vet " + vetLogin + " assigned to pet " + petId) .build(); } catch (IllegalArgumentException e) { return Response.status(Response.Status.NOT_FOUND) @@ -218,16 +219,13 @@ public class VetResource { @DELETE @Path("{login}/unassign/pets/{petId}") public Response unassignVetFromPet( - //@PathParam("login") String vetLogin, @PathParam("petId") Long petId ) { - //requireNonNull(vetLogin, "vetLogin can't be null"); requireNonNull(petId, "petId can't be null"); try { petService.unassignVetFromPet(petId); return Response.ok() - //.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/AdministratorService.java b/service/src/main/java/es/uvigo/esei/xcs/service/AdministratorService.java index 0bbce93a4c6ebdf991b693f5f43338c3dc0b648e..ee3558b6c26391d308759f031d37ec20b1b748f8 100644 --- a/service/src/main/java/es/uvigo/esei/xcs/service/AdministratorService.java +++ b/service/src/main/java/es/uvigo/esei/xcs/service/AdministratorService.java @@ -32,7 +32,7 @@ public class AdministratorService { throw new IllegalArgumentException("The page size can't be negative or zero"); } return em.createQuery("SELECT DISTINCT u FROM User u", User.class) - .setFirstResult((page - 1) * pageSize) + .setFirstResult(page * pageSize) .setMaxResults(pageSize) .getResultList(); diff --git a/service/src/main/java/es/uvigo/esei/xcs/service/OwnerService.java b/service/src/main/java/es/uvigo/esei/xcs/service/OwnerService.java index 008d1b5bffa1e7086d2f41fb67d56aa4fa0a6490..2b7b847a42ae07841f949af033a17f504216d855 100644 --- a/service/src/main/java/es/uvigo/esei/xcs/service/OwnerService.java +++ b/service/src/main/java/es/uvigo/esei/xcs/service/OwnerService.java @@ -25,7 +25,7 @@ import es.uvigo.esei.xcs.domain.entities.Vaccination; * @author Miguel Reboiro Jato */ @Stateless -@RolesAllowed("ADMIN") +@RolesAllowed({"ADMIN", "OWNER"}) public class OwnerService { @PersistenceContext private EntityManager em; @@ -160,13 +160,11 @@ public class OwnerService { public List getVaccinationsFromOwnPet( - String login, IdentifierType identifierType, String identifierValue, int page, int pageSize ){ - 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"); @@ -183,10 +181,10 @@ public class OwnerService { + "JOIN p.vaccinations v " + "WHERE " + "o.login = :login AND " - + "i.identifierType = :identifierType AND " - + "i.identifierValue = :identifierValue", + + "i.type = :identifierType AND " + + "i.value = :identifierValue", Vaccination.class) - .setParameter("login", login) + .setParameter("login", currentUser.getName()) .setParameter("identifierType", identifierType) .setParameter("identifierValue", identifierValue) .setFirstResult(page * pageSize) 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 e4162799577da22d4c9d116fb0a6ac2b3d46ce2e..924e818fbcb7abdd4118ac243688ef1c777bd780 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 @@ -31,7 +31,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet; */ @Stateless @RolesAllowed({"VET", "OWNER"}) -//@PermitAll public class PetService { @Inject private Principal currentUser; diff --git a/service/src/main/java/es/uvigo/esei/xcs/service/VaccinationService.java b/service/src/main/java/es/uvigo/esei/xcs/service/VaccinationService.java index 7864937a66d2c2a6a71ef1eabb962d0c2c54a3b9..b33abf9bd0bb8a224bb22519b465bb68ae903b79 100644 --- a/service/src/main/java/es/uvigo/esei/xcs/service/VaccinationService.java +++ b/service/src/main/java/es/uvigo/esei/xcs/service/VaccinationService.java @@ -54,24 +54,6 @@ public class VaccinationService { } - /*public Vaccination create(int petId, int vaccineId, String textDate) { - Pet pet = requireNonNull(em.find(Pet.class, petId), "Pet can't be null"); - Vaccine vaccine = requireNonNull(em.find(Vaccine.class, vaccineId), "Vaccine can't be null"); - Date date = new Date(); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - if(textDate != null) { - try { - date = format.parse(textDate); - } catch (ParseException e) { - date = null; - } - } - - Vaccination vaccination = new Vaccination(pet, vaccine, date); - em.persist(vaccination); - return vaccination; - }*/ - public Vaccination create(Long petId, Long vaccineId, Date date) { Pet pet = requireNonNull(em.find(Pet.class, petId), "Pet can't be null"); Vaccine vaccine = requireNonNull(em.find(Vaccine.class, vaccineId), "Vaccine can't be null"); 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 6cc68800cd93edf3edcf460b95de0d2923dd92e0..1d20eda3268b8798cd3353713fcdda7a6d5e15f0 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 @@ -18,7 +18,6 @@ import es.uvigo.esei.xcs.domain.entities.Pet; import es.uvigo.esei.xcs.domain.entities.Vaccine; @Stateless -//@PermitAll @RolesAllowed("VET") public class VaccineService { @PersistenceContext 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 7b6d1d0aaad5a4ae1728d9bb51c3d1d9c46d0f1a..fb5f2cf16890112bbc986557e2b137aced3e86e2 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 @@ -19,7 +19,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet; @Stateless @RolesAllowed("VET") -//@PermitAll public class VetService { @Inject private Principal currentUser; @@ -83,7 +82,6 @@ public class VetService { public List getPets(int first , int pageSize) { - //requireNonNull(login, "Login can't be null"); if (first < 0) throw new IllegalArgumentException("First can't be negative"); if (pageSize <= 0) throw new IllegalArgumentException("Page size must be positive"); @@ -96,13 +94,11 @@ public class VetService { } public List getVaccinationsFromOwnPet( - //String login, IdentifierType identifierType, String identifierValue, int page, int pageSize ){ - //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) { @@ -118,8 +114,8 @@ public class VetService { + "JOIN p.vaccinations v " + "WHERE " + "vet.login = :login AND " - + "i.identifierType = :identifierType AND " - + "i.identifierValue = :identifierValue", + + "i.type = :identifierType AND " + + "i.value = :identifierValue", Vaccination.class) .setParameter("login", currentUser.getName()) .setParameter("identifierType", identifierType) @@ -129,9 +125,5 @@ public class VetService { .getResultList(); } - public void assignPetToVet() { - - } - }