Package org.springframework.samples.petclinic.model

Examples of org.springframework.samples.petclinic.model.Owner


     * Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
     * for the corresponding owner, if not already loaded.
     */
    @Override
    public Owner findById(int id) throws DataAccessException {
        Owner owner;
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("id", id);
            owner = this.namedParameterJdbcTemplate.queryForObject(
                    "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
View Full Code Here


                    params,
                    new JdbcPetRowMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
        }
        Owner owner = this.ownerRepository.findById(pet.getOwnerId());
        owner.addPet(pet);
        pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

        List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
        for (Visit visit : visits) {
            pet.addVisit(visit);
View Full Code Here

        dataBinder.setDisallowedFields("id");
    }

    @RequestMapping(value = "/owners/new", method = RequestMethod.GET)
    public String initCreationForm(Map<String, Object> model) {
        Owner owner = new Owner();
        model.put("owner", owner);
        return "owners/createOrUpdateOwnerForm";
    }
View Full Code Here

        }
    }

    @RequestMapping(value = "/owners/find", method = RequestMethod.GET)
    public String initFindForm(Map<String, Object> model) {
        model.put("owner", new Owner());
        return "owners/findOwners";
    }
View Full Code Here

        }
    }

    @RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET)
    public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
        Owner owner = this.clinicService.findOwnerById(ownerId);
        model.addAttribute(owner);
        return "owners/createOrUpdateOwnerForm";
    }
View Full Code Here

        dataBinder.setDisallowedFields("id");
    }

    @RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.GET)
    public String initCreationForm(@PathVariable("ownerId") int ownerId, Map<String, Object> model) {
        Owner owner = this.clinicService.findOwnerById(ownerId);
        Pet pet = new Pet();
        owner.addPet(pet);
        model.put("pet", pet);
        return "pets/createOrUpdatePetForm";
    }
View Full Code Here

        assertEquals(0, owners.size());
    }

    @Test
    public void findSingleOwner() {
        Owner owner1 = this.clinicService.findOwnerById(1);
        assertTrue(owner1.getLastName().startsWith("Franklin"));
        Owner owner10 = this.clinicService.findOwnerById(10);
        assertEquals("Carlos", owner10.getFirstName());

        assertEquals(owner1.getPets().size(), 1);
    }
View Full Code Here

    @Test
    @Transactional
    public void insertOwner() {
        Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz");
        int found = owners.size();
        Owner owner = new Owner();
        owner.setFirstName("Sam");
        owner.setLastName("Schultz");
        owner.setAddress("4, Evans Street");
        owner.setCity("Wollongong");
        owner.setTelephone("4444444444");
        this.clinicService.saveOwner(owner);
        Assert.assertNotEquals("Owner Id should have been generated", owner.getId().longValue(), 0);
        owners = this.clinicService.findOwnerByLastName("Schultz");
        assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size());
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void updateOwner() throws Exception {
        Owner o1 = this.clinicService.findOwnerById(1);
        String old = o1.getLastName();
        o1.setLastName(old + "X");
        this.clinicService.saveOwner(o1);
        o1 = this.clinicService.findOwnerById(1);
        assertEquals(old + "X", o1.getLastName());
    }
View Full Code Here

  }

  @Test
  @Transactional
  public void insertPet() {
      Owner owner6 = this.clinicService.findOwnerById(6);
      int found = owner6.getPets().size();
      Pet pet = new Pet();
      pet.setName("bowser");
      Collection<PetType> types = this.clinicService.findPetTypes();
      pet.setType(EntityUtils.getById(types, PetType.class, 2));
      pet.setBirthDate(new DateTime());
      owner6.addPet(pet);
      assertEquals(found + 1, owner6.getPets().size());
      // both storePet and storeOwner are necessary to cover all ORM tools
      this.clinicService.savePet(pet);
      this.clinicService.saveOwner(owner6);
      owner6 = this.clinicService.findOwnerById(6);
      assertEquals(found + 1, owner6.getPets().size());
      assertNotNull("Pet Id should have been generated", pet.getId());
  }
View Full Code Here

TOP

Related Classes of org.springframework.samples.petclinic.model.Owner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.