Search in sources :

Example 1 with PersonAddress

use of gov.ca.cwds.data.persistence.ns.PersonAddress in project API by ca-cwds.

the class PersonService method populatePersonDetails.

/**
   * 
   * @param person - The person
   * @param managedPerson - The managedPerson
   */
private void populatePersonDetails(Person person, gov.ca.cwds.data.persistence.ns.Person managedPerson) {
    if (person.getAddress() != null && !person.getAddress().isEmpty()) {
        for (Address address : person.getAddress()) {
            gov.ca.cwds.data.persistence.ns.Address managedAddress = new gov.ca.cwds.data.persistence.ns.Address(address, null, null);
            PersonAddress personAddress = new PersonAddress(managedPerson, managedAddress);
            managedPerson.addPersonAddress(personAddress);
            addressDao.create(managedAddress);
            personAddressDao.create(personAddress);
        }
    }
    if (person.getPhoneNumber() != null && !person.getPhoneNumber().isEmpty()) {
        for (PhoneNumber phoneNumber : person.getPhoneNumber()) {
            gov.ca.cwds.data.persistence.ns.PhoneNumber managedPhoneNumber = new gov.ca.cwds.data.persistence.ns.PhoneNumber(phoneNumber, null, null);
            PersonPhone personPhone = new PersonPhone(managedPerson, managedPhoneNumber);
            managedPerson.addPersonPhone(personPhone);
            phoneNumberDao.create(managedPhoneNumber);
            personPhoneDao.create(personPhone);
        }
    }
    if (person.getLanguage() != null && !person.getLanguage().isEmpty()) {
        for (Language language : person.getLanguage()) {
            gov.ca.cwds.data.persistence.ns.Language managedLanguage = new gov.ca.cwds.data.persistence.ns.Language(language, null, null);
            PersonLanguage personLanguage = new PersonLanguage(managedPerson, managedLanguage);
            managedPerson.addPersonLanguage(personLanguage);
            languageDao.create(managedLanguage);
            personLanguageDao.create(personLanguage);
        }
    }
    if (person.getRace() != null && !person.getRace().isEmpty()) {
        for (Race race : person.getRace()) {
            gov.ca.cwds.data.persistence.ns.Race managedRace = new gov.ca.cwds.data.persistence.ns.Race(race, null, null);
            PersonRace personRace = new PersonRace(managedPerson, managedRace);
            managedPerson.addPersonRace(personRace);
            raceDao.create(managedRace);
            personRaceDao.create(personRace);
        }
    }
    if (person.getEthnicity() != null && !person.getEthnicity().isEmpty()) {
        for (Ethnicity ethnicity : person.getEthnicity()) {
            gov.ca.cwds.data.persistence.ns.Ethnicity managedEthnicity = new gov.ca.cwds.data.persistence.ns.Ethnicity(ethnicity, null, null);
            PersonEthnicity personEthnicity = new PersonEthnicity(managedPerson, managedEthnicity);
            managedPerson.addPersonEthnicity(personEthnicity);
            ethnicityDao.create(managedEthnicity);
            personEthnicityDao.create(personEthnicity);
        }
    }
}
Also used : PersonRace(gov.ca.cwds.data.persistence.ns.PersonRace) PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) Address(gov.ca.cwds.rest.api.domain.Address) PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) PersonLanguage(gov.ca.cwds.data.persistence.ns.PersonLanguage) PersonPhone(gov.ca.cwds.data.persistence.ns.PersonPhone) Ethnicity(gov.ca.cwds.rest.api.domain.Ethnicity) PersonEthnicity(gov.ca.cwds.data.persistence.ns.PersonEthnicity) Language(gov.ca.cwds.rest.api.domain.Language) PersonLanguage(gov.ca.cwds.data.persistence.ns.PersonLanguage) PersonRace(gov.ca.cwds.data.persistence.ns.PersonRace) Race(gov.ca.cwds.rest.api.domain.Race) PersonEthnicity(gov.ca.cwds.data.persistence.ns.PersonEthnicity) PhoneNumber(gov.ca.cwds.rest.api.domain.PhoneNumber)

Example 2 with PersonAddress

use of gov.ca.cwds.data.persistence.ns.PersonAddress in project API by ca-cwds.

the class PersonServiceTest method createReturnsPostedPerson.

/*
   * create tests
   */
@Test
public void createReturnsPostedPerson() throws Exception {
    gov.ca.cwds.data.persistence.ns.Address toCreateAddress = new gov.ca.cwds.data.persistence.ns.Address(1L, "742 Evergreen Terrace", "Springfield", "WA", new Integer(98700), "Home");
    Set<PersonAddress> personAddresses = new HashSet<>();
    PersonAddress personAddress = new PersonAddress();
    personAddress.setAddress(toCreateAddress);
    personAddresses.add(personAddress);
    gov.ca.cwds.data.persistence.ns.Person toCreate = new gov.ca.cwds.data.persistence.ns.Person(2L, "Bart", "Simpson", "M", DomainChef.uncookDateString("2013-10-31"), "1234556789", personAddresses, null, null, null, null);
    Person request = new Person(toCreate);
    when(personDao.create(any(gov.ca.cwds.data.persistence.ns.Person.class))).thenReturn(toCreate);
    when(personDao.find(any(gov.ca.cwds.data.persistence.ns.Person.class))).thenReturn(toCreate);
    Response response = personService.create(request);
    assertThat(response.getClass(), is(PostedPerson.class));
}
Also used : PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) Address(gov.ca.cwds.rest.api.domain.Address) PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) Response(gov.ca.cwds.rest.api.Response) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with PersonAddress

use of gov.ca.cwds.data.persistence.ns.PersonAddress in project API by ca-cwds.

the class PersonServiceTest method createReturnsNonNull.

@Test
public void createReturnsNonNull() throws Exception {
    gov.ca.cwds.data.persistence.ns.Address toCreateAddress = new gov.ca.cwds.data.persistence.ns.Address(1L, "742 Evergreen Terrace", "Springfield", "WA", new Integer(98700), "Home");
    Set<PersonAddress> personAddresses = new HashSet<>();
    PersonAddress personAddress = new PersonAddress();
    personAddress.setAddress(toCreateAddress);
    personAddresses.add(personAddress);
    gov.ca.cwds.data.persistence.ns.Person toCreate = new gov.ca.cwds.data.persistence.ns.Person(2L, "Bart", "Simpson", "M", DomainChef.uncookDateString("2016-10-31"), "1234556789", personAddresses, null, null, null, null);
    Person request = new Person(toCreate);
    when(personDao.create(any(gov.ca.cwds.data.persistence.ns.Person.class))).thenReturn(toCreate);
    when(personDao.find(any(gov.ca.cwds.data.persistence.ns.Person.class))).thenReturn(toCreate);
    PostedPerson postedPerson = personService.create(request);
    assertThat(postedPerson, is(notNullValue()));
}
Also used : PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) Address(gov.ca.cwds.rest.api.domain.Address) PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with PersonAddress

use of gov.ca.cwds.data.persistence.ns.PersonAddress in project API by ca-cwds.

the class PersonDaoIT method testCreate.

@Override
@Test
public void testCreate() {
    gov.ca.cwds.data.persistence.ns.Address toCreateAddress = new gov.ca.cwds.data.persistence.ns.Address(1L, "742 Evergreen Terrace", "Springfield", "WA", new Integer(98700), "Home");
    Set<PersonAddress> personAddresses = new HashSet<>();
    PersonAddress personAddress = new PersonAddress();
    personAddress.setAddress(toCreateAddress);
    personAddresses.add(personAddress);
    Person person = new Person(null, "John", "Doe", "Male", new Date(), "111-11-1111", personAddresses, null, null, null, null);
    Person created = personDao.create(person);
    assertThat(created, is(person));
}
Also used : PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) Date(java.util.Date) Person(gov.ca.cwds.data.persistence.ns.Person) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

PersonAddress (gov.ca.cwds.data.persistence.ns.PersonAddress)4 Address (gov.ca.cwds.rest.api.domain.Address)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 Person (gov.ca.cwds.rest.api.domain.Person)2 PostedPerson (gov.ca.cwds.rest.api.domain.PostedPerson)2 Person (gov.ca.cwds.data.persistence.ns.Person)1 PersonEthnicity (gov.ca.cwds.data.persistence.ns.PersonEthnicity)1 PersonLanguage (gov.ca.cwds.data.persistence.ns.PersonLanguage)1 PersonPhone (gov.ca.cwds.data.persistence.ns.PersonPhone)1 PersonRace (gov.ca.cwds.data.persistence.ns.PersonRace)1 Response (gov.ca.cwds.rest.api.Response)1 Ethnicity (gov.ca.cwds.rest.api.domain.Ethnicity)1 Language (gov.ca.cwds.rest.api.domain.Language)1 PhoneNumber (gov.ca.cwds.rest.api.domain.PhoneNumber)1 Race (gov.ca.cwds.rest.api.domain.Race)1 Date (java.util.Date)1