@Override @GET @Path("/petTypes") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response findPetTypes() { try { Result<List<PetType>> response = petClinicMgr.findAllPetTypes(); ServiceResponse<PetTypeSrvMdlList> responseMessage = ResponseTranslator.toServiceResponse(response); if (response.isSuccess()) { List<PetType> petTypeList = response.getResult(); if (!CollectionUtils.isEmpty(petTypeList)) { List<PetTypeSrvMdl> petTypeSrvMdlList = new ArrayList<PetTypeSrvMdl>(petTypeList.size()); for (PetType petType : petTypeList) { petTypeSrvMdlList.add(ResponseTranslator.transform(petType)); } responseMessage.setResult(new PetTypeSrvMdlList(petTypeSrvMdlList)); } } return Response.ok(responseMessage).build(); } catch (Exception ex) { ex.printStackTrace(); } return Response.ok(ServiceResponse.failure()).build(); }
@Override @GET @Path("/vets") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response findAllVets() { try { Result<List<Vet>> response = petClinicMgr.findAllVets(); ServiceResponse<VetSrvMdlList> responseMessage = ResponseTranslator.toServiceResponse(response); if (response.isSuccess()) { List<Vet> vets = response.getResult(); if (!CollectionUtils.isEmpty(vets)) { List<VetSrvMdl> vetSrvMdls = new ArrayList<VetSrvMdl>(vets.size()); for (Vet vet : vets) { vetSrvMdls.add(ResponseTranslator.transform(vet)); } VetSrvMdlList vetSrvMdlList = new VetSrvMdlList(vetSrvMdls); responseMessage.setResult(vetSrvMdlList); } } return Response.ok(responseMessage).build(); } catch (Exception ex) { ex.printStackTrace(); } return Response.ok(ServiceResponse.failure()).build(); }
// TODO: proper search API implementation @Override @GET @Path("/owner/search") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response findOwnerByLastName(@QueryParam("lastName") String lastName) { try { Result<List<Owner>> response = petClinicMgr.findOwnerByLastName(lastName); ServiceResponse<OwnerSrvMdlList> responseMessage = ResponseTranslator.toServiceResponse(response); if (response.isSuccess()) { List<Owner> owners = response.getResult(); if (!CollectionUtils.isEmpty(owners)) { List<OwnerSrvMdl> ownerSrvMdlList = new ArrayList<OwnerSrvMdl>(owners.size()); for (Owner owner : owners) { ownerSrvMdlList.add(ResponseTranslator.transform(owner)); } responseMessage.setResult(new OwnerSrvMdlList(ownerSrvMdlList)); } } return Response.ok(responseMessage).build(); } catch (Exception ex) { ex.printStackTrace(); } return Response.ok(ServiceResponse.failure()).build(); }
@Override @GET @Path("/pets/{petId}") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response findPetById(@PathParam("petId") long petId) { try { Result<Pet> response = petClinicMgr.findPetById(petId); ServiceResponse<PetSrvMdl> responseMessage = ResponseTranslator.toServiceResponse(response); if (response.isSuccess()) { PetSrvMdl petSrvMdl = ResponseTranslator.transform(response.getResult()); responseMessage.setResult(petSrvMdl); } return Response.ok(responseMessage).build(); } catch (Exception ex) { } return Response.ok(ServiceResponse.failure()).build(); }
@Override @GET @Path("/owners/{ownerId}") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response findOwnerById(@PathParam("ownerId") long ownerId) { try { Result<Owner> bussniesResponse = petClinicMgr.findOwnerById(ownerId); ServiceResponse<OwnerSrvMdl> responseMessage = ResponseTranslator.toServiceResponse(bussniesResponse); if (bussniesResponse.isSuccess()) { OwnerSrvMdl ownerSrvMdl = ResponseTranslator.transform(bussniesResponse.getResult()); responseMessage.setResult(ownerSrvMdl); } return Response.ok(responseMessage).build(); } catch (Exception ex) { ex.printStackTrace(); } return Response.ok(ServiceResponse.failure()).build(); }