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;
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<Vaccine> allVaccines;
@PostConstruct
......
......@@ -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<Pet> getPets() {
List<Pet> 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);
}
......
......@@ -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<Vaccine> 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<Vaccine> 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;
}
}
......@@ -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<Vet> getVets() {
return this.service.list();
}
/*public List<Pet> getPets() {
return this.service.getPets(0, 100);
}*/
public String getPetNames() {
return this.service.getPets(0, 100).stream()
......
......@@ -14,7 +14,6 @@
<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>
......
......@@ -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,
......
......@@ -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) {
......
......@@ -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(),
......
......@@ -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)
......
......@@ -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();
......
......@@ -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<Vaccination> 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)
......
......@@ -31,7 +31,6 @@ import es.uvigo.esei.xcs.domain.entities.Vet;
*/
@Stateless
@RolesAllowed({"VET", "OWNER"})
//@PermitAll
public class PetService {
@Inject
private Principal currentUser;
......
......@@ -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");
......
......@@ -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
......
......@@ -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<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 (pageSize <= 0) throw new IllegalArgumentException("Page size must be positive");
......@@ -96,13 +94,11 @@ public class VetService {
}
public List<Vaccination> 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() {
}
}
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