Commit 3ef867d3 authored by Breixo Senra's avatar Breixo Senra

Proyecto casi acabado

parent 36f83ffd
...@@ -24,7 +24,6 @@ import es.uvigo.esei.xcs.service.VaccinationService; ...@@ -24,7 +24,6 @@ import es.uvigo.esei.xcs.service.VaccinationService;
import es.uvigo.esei.xcs.service.VaccineService; import es.uvigo.esei.xcs.service.VaccineService;
@Named("petDetails") @Named("petDetails")
//@RequestScoped
@ViewScoped @ViewScoped
public class PetDetailsManagedBean implements Serializable{ public class PetDetailsManagedBean implements Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -42,7 +41,7 @@ public class PetDetailsManagedBean implements Serializable{ ...@@ -42,7 +41,7 @@ public class PetDetailsManagedBean implements Serializable{
private Pet pet; private Pet pet;
private Long selectedVaccineId; private Long selectedVaccineId;
private Date vaccinationDate; // yyyy-MM-dd private Date vaccinationDate;
private List<Vaccine> allVaccines; private List<Vaccine> allVaccines;
@PostConstruct @PostConstruct
......
...@@ -22,7 +22,6 @@ import es.uvigo.esei.xcs.domain.entities.Pet; ...@@ -22,7 +22,6 @@ import es.uvigo.esei.xcs.domain.entities.Pet;
import es.uvigo.esei.xcs.service.PetService; import es.uvigo.esei.xcs.service.PetService;
@Named("pet") @Named("pet")
//@RequestScoped
@ViewScoped @ViewScoped
public class PetManagedBean implements Serializable{ public class PetManagedBean implements Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -119,14 +118,7 @@ public class PetManagedBean implements Serializable{ ...@@ -119,14 +118,7 @@ public class PetManagedBean implements Serializable{
this.id = id; this.id = id;
} }
/*public List<Pet> getPets() {
List<Pet> list = this.service.getAll(0, 100);
System.out.println(list);
return list;
}*/
public String edit(Long petId) { public String edit(Long petId) {
//throw new RuntimeException("ERROR GRAVE (" + petId + ")");
final Pet pet = this.service.get(petId); final Pet pet = this.service.get(petId);
this.id = pet.getId(); this.id = pet.getId();
...@@ -134,7 +126,7 @@ public class PetManagedBean implements Serializable{ ...@@ -134,7 +126,7 @@ public class PetManagedBean implements Serializable{
this.birth = pet.getBirth(); this.birth = pet.getBirth();
this.animal = pet.getAnimal(); this.animal = pet.getAnimal();
return null;// this.getViewId(); return null;
} }
public String cancelEditing() { public String cancelEditing() {
...@@ -159,7 +151,6 @@ public class PetManagedBean implements Serializable{ ...@@ -159,7 +151,6 @@ public class PetManagedBean implements Serializable{
this.service.update(pet); this.service.update(pet);
} else { } else {
//this.service.create(new Pet(name, animal, birth));
this.service.createPet(name, animal, birth); this.service.createPet(name, animal, birth);
} }
......
...@@ -11,7 +11,6 @@ import es.uvigo.esei.xcs.domain.entities.Vaccine; ...@@ -11,7 +11,6 @@ import es.uvigo.esei.xcs.domain.entities.Vaccine;
import es.uvigo.esei.xcs.service.VaccineService; import es.uvigo.esei.xcs.service.VaccineService;
@Named("vaccine") @Named("vaccine")
//@RequestScoped
@ViewScoped @ViewScoped
public class VaccineManagedBean implements Serializable{ public class VaccineManagedBean implements Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -42,18 +41,27 @@ public class VaccineManagedBean implements Serializable{ ...@@ -42,18 +41,27 @@ public class VaccineManagedBean implements Serializable{
vaccines = vaccineService.list(0, 100); vaccines = vaccineService.list(0, 100);
} }
private Vaccine selectedVaccine; // vacuna que vamos a editar private Vaccine selectedVaccine;
private String newName; // nuevo nombre para editar private String newName;
public Vaccine getSelectedVaccine() { return selectedVaccine; } public Vaccine getSelectedVaccine() {
return selectedVaccine;
}
public void setSelectedVaccine(Vaccine selectedVaccine) { public void setSelectedVaccine(Vaccine selectedVaccine) {
this.selectedVaccine = selectedVaccine; this.selectedVaccine = selectedVaccine;
if (selectedVaccine != null) { 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() { public void editVaccine() {
if (selectedVaccine != null && newName != null && !newName.trim().isEmpty()) { if (selectedVaccine != null && newName != null && !newName.trim().isEmpty()) {
...@@ -72,16 +80,49 @@ public class VaccineManagedBean implements Serializable{ ...@@ -72,16 +80,49 @@ public class VaccineManagedBean implements Serializable{
periodicType = null; periodicType = null;
} }
// Getters y setters
public List<Vaccine> getVaccines() { return vaccines; } public List<Vaccine> getVaccines() {
public String getName() { return name; } return vaccines;
public void setName(String name) { this.name = name; } }
public String getType() { return type; }
public void setType(String type) { this.type = type; } public String getName() {
public Integer getDoses() { return doses; } return name;
public void setDoses(Integer doses) { this.doses = doses; } }
public Integer getPeriode() { return periode; }
public void setPeriode(Integer periode) { this.periode = periode; } public void setName(String name) {
public String getPeriodicType() { return periodicType; } this.name = name;
public void setPeriodicType(String periodicType) { this.periodicType = periodicType; } }
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;
}
} }
...@@ -22,7 +22,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet; ...@@ -22,7 +22,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet;
import es.uvigo.esei.xcs.service.VetService; import es.uvigo.esei.xcs.service.VetService;
@Named("vet") @Named("vet")
//@RequestScoped
@ViewScoped @ViewScoped
public class VetManagedBean implements Serializable{ public class VetManagedBean implements Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -93,10 +92,6 @@ public class VetManagedBean implements Serializable{ ...@@ -93,10 +92,6 @@ public class VetManagedBean implements Serializable{
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() { public String getPetNames() {
return this.service.getPets(0, 100).stream() return this.service.getPets(0, 100).stream()
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
<ui:define name="jumbotron"> <ui:define name="jumbotron">
<h2>Welcome!</h2> <h2>Welcome!</h2>
<div>This is the Pet Store web page, where you can manage your pets. Please, login to continue.</div> <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:define>
</ui:composition> </ui:composition>
</body> </body>
......
...@@ -140,10 +140,9 @@ public class OwnerResource { ...@@ -140,10 +140,9 @@ public class OwnerResource {
} }
@Path("{login}/pet/{petIdentifierType}/{petIdentifierValue}/vaccination") @Path("pet/{petIdentifierType}/{petIdentifierValue}/vaccination")
@GET @GET
public Response listVaccinations( public Response listVaccinations(
@PathParam("login") String login,
@PathParam("petIdentifierType") IdentifierType petIdentifierType, @PathParam("petIdentifierType") IdentifierType petIdentifierType,
@PathParam("petIdentifierValue") String petIdentifierValue, @PathParam("petIdentifierValue") String petIdentifierValue,
@QueryParam("page") int page, @QueryParam("page") int page,
...@@ -151,7 +150,7 @@ public class OwnerResource { ...@@ -151,7 +150,7 @@ public class OwnerResource {
) { ) {
return Response.ok(this.service.getVaccinationsFromOwnPet( return Response.ok(this.service.getVaccinationsFromOwnPet(
login, //login,
petIdentifierType, petIdentifierType,
petIdentifierValue, petIdentifierValue,
page, page,
......
...@@ -43,7 +43,7 @@ public class VaccinationResource { ...@@ -43,7 +43,7 @@ public class VaccinationResource {
public Response createVaccination( public Response createVaccination(
@PathParam("petId") Long petId, @PathParam("petId") Long petId,
@PathParam("vaccineId") Long vaccineId, @PathParam("vaccineId") Long vaccineId,
@QueryParam("date") String textDate // opcional, formato yyyy-MM-dd @QueryParam("date") String textDate
) { ) {
Date date = new Date(); Date date = new Date();
if (textDate != null) { if (textDate != null) {
......
...@@ -32,7 +32,6 @@ public class VaccineResource { ...@@ -32,7 +32,6 @@ public class VaccineResource {
@POST @POST
public Response create(VaccineCreationData vaccineData) { public Response create(VaccineCreationData vaccineData) {
requireNonNull(vaccineData, "vaccineData can't be null"); requireNonNull(vaccineData, "vaccineData can't be null");
//Vaccine vaccine = vaccineService.create(vaccineData.toVaccine());
Vaccine vaccine = vaccineService.create( Vaccine vaccine = vaccineService.create(
vaccineData.getName(), vaccineData.getName(),
vaccineData.getType(), vaccineData.getType(),
......
...@@ -100,12 +100,9 @@ public class VetResource { ...@@ -100,12 +100,9 @@ public class VetResource {
@GET @GET
@Path("pets") @Path("pets")
public Response listPets( public Response listPets(
//@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");
return Response.ok(this.vetService.getPets(page, pageSize)).build(); return Response.ok(this.vetService.getPets(page, pageSize)).build();
} }
...@@ -124,10 +121,16 @@ public class VetResource { ...@@ -124,10 +121,16 @@ public class VetResource {
} }
@Path("vaccine")
@POST @POST
@Path("vaccine")
public Response createVaccine(VaccineCreationData vaccineData) { 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(); return Response.ok(vaccine).build();
} }
...@@ -155,16 +158,14 @@ public class VetResource { ...@@ -155,16 +158,14 @@ public class VetResource {
} }
} }
@Path("pets/{petIdentifierType}/{petIdentifierValue}/vaccination") @Path("pet/{petIdentifierType}/{petIdentifierValue}/vaccination")
@GET @GET
public Response listVaccinations( public Response listVaccinations(
@PathParam("login") String login,
@PathParam("petIdentifierType") IdentifierType petIdentifierType, @PathParam("petIdentifierType") IdentifierType petIdentifierType,
@PathParam("petIdentifierValue") String petIdentifierValue, @PathParam("petIdentifierValue") String petIdentifierValue,
@QueryParam("page") int page, @QueryParam("page") int page,
@QueryParam("pageSize") int pageSize @QueryParam("pageSize") int pageSize
) { ) {
requireNonNull(login, "login can't be null");
return Response.ok(this.vetService.getVaccinationsFromOwnPet( return Response.ok(this.vetService.getVaccinationsFromOwnPet(
//login, //login,
...@@ -175,12 +176,15 @@ public class VetResource { ...@@ -175,12 +176,15 @@ public class VetResource {
)).build(); )).build();
} }
@Path("pets/{petIdentifierType}/{petIdentifierValue}/vaccination") @Path("vaccination")
@POST @POST
public Response registerVaccination( public Response registerVaccination(
@QueryParam("date") Date date, @QueryParam("date") Date date,
VaccinationCreationData vaccinationData VaccinationCreationData vaccinationData
) { ) {
if (date == null) {
date = new Date();
}
Vaccination vaccination = this.vaccinationService.create( Vaccination vaccination = this.vaccinationService.create(
vaccinationData.getPetId(), vaccinationData.getPetId(),
vaccinationData.getVaccineId(), vaccinationData.getVaccineId(),
...@@ -197,16 +201,13 @@ public class VetResource { ...@@ -197,16 +201,13 @@ public class VetResource {
@POST @POST
@Path("/assign/pets/{petId}") @Path("/assign/pets/{petId}")
public Response assignVetToPet( public Response assignVetToPet(
//@PathParam("login") String vetLogin,
@PathParam("petId") Long petId @PathParam("petId") Long petId
) { ) {
//requireNonNull(vetLogin, "vetLogin can't be null");
requireNonNull(petId, "petId can't be null"); requireNonNull(petId, "petId can't be null");
try { try {
petService.assignVetToPet(petId); petService.assignVetToPet(petId);
return Response.ok() return Response.ok()
//.entity("Vet " + vetLogin + " assigned to pet " + petId)
.build(); .build();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND)
...@@ -218,16 +219,13 @@ public class VetResource { ...@@ -218,16 +219,13 @@ public class VetResource {
@DELETE @DELETE
@Path("{login}/unassign/pets/{petId}") @Path("{login}/unassign/pets/{petId}")
public Response unassignVetFromPet( public Response unassignVetFromPet(
//@PathParam("login") String vetLogin,
@PathParam("petId") Long petId @PathParam("petId") Long petId
) { ) {
//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); petService.unassignVetFromPet(petId);
return Response.ok() return Response.ok()
//.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)
......
...@@ -32,7 +32,7 @@ public class AdministratorService { ...@@ -32,7 +32,7 @@ public class AdministratorService {
throw new IllegalArgumentException("The page size can't be negative or zero"); throw new IllegalArgumentException("The page size can't be negative or zero");
} }
return em.createQuery("SELECT DISTINCT u FROM User u", User.class) return em.createQuery("SELECT DISTINCT u FROM User u", User.class)
.setFirstResult((page - 1) * pageSize) .setFirstResult(page * pageSize)
.setMaxResults(pageSize) .setMaxResults(pageSize)
.getResultList(); .getResultList();
......
...@@ -25,7 +25,7 @@ import es.uvigo.esei.xcs.domain.entities.Vaccination; ...@@ -25,7 +25,7 @@ import es.uvigo.esei.xcs.domain.entities.Vaccination;
* @author Miguel Reboiro Jato * @author Miguel Reboiro Jato
*/ */
@Stateless @Stateless
@RolesAllowed("ADMIN") @RolesAllowed({"ADMIN", "OWNER"})
public class OwnerService { public class OwnerService {
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
...@@ -160,13 +160,11 @@ public class OwnerService { ...@@ -160,13 +160,11 @@ public class OwnerService {
public List<Vaccination> getVaccinationsFromOwnPet( public List<Vaccination> getVaccinationsFromOwnPet(
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(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");
...@@ -183,10 +181,10 @@ public class OwnerService { ...@@ -183,10 +181,10 @@ public class OwnerService {
+ "JOIN p.vaccinations v " + "JOIN p.vaccinations v "
+ "WHERE " + "WHERE "
+ "o.login = :login AND " + "o.login = :login AND "
+ "i.identifierType = :identifierType AND " + "i.type = :identifierType AND "
+ "i.identifierValue = :identifierValue", + "i.value = :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)
......
...@@ -31,7 +31,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet; ...@@ -31,7 +31,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet;
*/ */
@Stateless @Stateless
@RolesAllowed({"VET", "OWNER"}) @RolesAllowed({"VET", "OWNER"})
//@PermitAll
public class PetService { public class PetService {
@Inject @Inject
private Principal currentUser; private Principal currentUser;
......
...@@ -54,24 +54,6 @@ public class VaccinationService { ...@@ -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) { public Vaccination create(Long petId, Long vaccineId, Date date) {
Pet pet = requireNonNull(em.find(Pet.class, petId), "Pet can't be null"); 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"); Vaccine vaccine = requireNonNull(em.find(Vaccine.class, vaccineId), "Vaccine can't be null");
......
...@@ -18,7 +18,6 @@ import es.uvigo.esei.xcs.domain.entities.Pet; ...@@ -18,7 +18,6 @@ import es.uvigo.esei.xcs.domain.entities.Pet;
import es.uvigo.esei.xcs.domain.entities.Vaccine; import es.uvigo.esei.xcs.domain.entities.Vaccine;
@Stateless @Stateless
//@PermitAll
@RolesAllowed("VET") @RolesAllowed("VET")
public class VaccineService { public class VaccineService {
@PersistenceContext @PersistenceContext
......
...@@ -19,7 +19,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet; ...@@ -19,7 +19,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet;
@Stateless @Stateless
@RolesAllowed("VET") @RolesAllowed("VET")
//@PermitAll
public class VetService { public class VetService {
@Inject @Inject
private Principal currentUser; private Principal currentUser;
...@@ -83,7 +82,6 @@ public class VetService { ...@@ -83,7 +82,6 @@ public class VetService {
public List<Pet> getPets(int first , int pageSize) { public List<Pet> getPets(int first , int pageSize) {
//requireNonNull(login, "Login can't be null");
if (first < 0) throw new IllegalArgumentException("First can't be negative"); if (first < 0) throw new IllegalArgumentException("First can't be negative");
if (pageSize <= 0) throw new IllegalArgumentException("Page size must be positive"); if (pageSize <= 0) throw new IllegalArgumentException("Page size must be positive");
...@@ -96,13 +94,11 @@ public class VetService { ...@@ -96,13 +94,11 @@ public class VetService {
} }
public List<Vaccination> getVaccinationsFromOwnPet( public List<Vaccination> getVaccinationsFromOwnPet(
//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(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) {
...@@ -118,8 +114,8 @@ public class VetService { ...@@ -118,8 +114,8 @@ public class VetService {
+ "JOIN p.vaccinations v " + "JOIN p.vaccinations v "
+ "WHERE " + "WHERE "
+ "vet.login = :login AND " + "vet.login = :login AND "
+ "i.identifierType = :identifierType AND " + "i.type = :identifierType AND "
+ "i.identifierValue = :identifierValue", + "i.value = :identifierValue",
Vaccination.class) Vaccination.class)
.setParameter("login", currentUser.getName()) .setParameter("login", currentUser.getName())
.setParameter("identifierType", identifierType) .setParameter("identifierType", identifierType)
...@@ -129,9 +125,5 @@ public class VetService { ...@@ -129,9 +125,5 @@ public class VetService {
.getResultList(); .getResultList();
} }
public void assignPetToVet() {
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment