Search in sources :

Example 1 with PostedPerson

use of gov.ca.cwds.rest.api.domain.PostedPerson in project API by ca-cwds.

the class PersonService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
@UnitOfWork(value = "ns")
public PostedPerson create(Request request) {
    assert request instanceof Person;
    Person person = (Person) request;
    gov.ca.cwds.data.persistence.ns.Person managedPerson = new gov.ca.cwds.data.persistence.ns.Person(person, null, null);
    managedPerson = personDao.create(managedPerson);
    populatePersonDetails(person, managedPerson);
    managedPerson = personDao.find(managedPerson.getId());
    PostedPerson postedPerson = new PostedPerson(managedPerson);
    try {
        final gov.ca.cwds.rest.api.domain.es.Person esPerson = new gov.ca.cwds.rest.api.domain.es.Person(managedPerson.getId().toString(), managedPerson.getFirstName(), managedPerson.getLastName(), managedPerson.getGender(), DomainChef.cookDate(managedPerson.getDateOfBirth()), managedPerson.getSsn(), managedPerson.getClass().getName(), MAPPER.writeValueAsString(managedPerson));
        final String document = MAPPER.writeValueAsString(esPerson);
        // If the people index is missing, create it.
        elasticsearchDao.createIndexIfNeeded(elasticsearchDao.getDefaultAlias());
    // The ES Dao manages its own connections. No need to manually start or stop.
    // elasticsearchDao.index(elasticsearchDao.getDefaultAlias(),
    // elasticsearchDao.getDefaultDocType(), document, esPerson.getId());
    } catch (Exception e) {
        LOGGER.error("Unable to Index Person in ElasticSearch", e);
        throw new ApiException("Unable to Index Person in ElasticSearch", e);
    }
    return postedPerson;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) ApiException(gov.ca.cwds.rest.api.ApiException) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) ApiException(gov.ca.cwds.rest.api.ApiException) UnitOfWork(io.dropwizard.hibernate.UnitOfWork)

Example 2 with PostedPerson

use of gov.ca.cwds.rest.api.domain.PostedPerson in project API by ca-cwds.

the class PersonService method update.

/**
   * <strong>NOT IMPLEMENTED! REQUIRED BY {@link CrudsService}!</strong> {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#update(java.io.Serializable,
   *      gov.ca.cwds.rest.api.Request)
   */
@Override
public Response update(final Serializable primaryKey, Request request) {
    assert primaryKey instanceof Long;
    assert request instanceof Person;
    Person person = (Person) request;
    gov.ca.cwds.data.persistence.ns.Person managedPerson = new gov.ca.cwds.data.persistence.ns.Person(person, null, null);
    managedPerson = personDao.update(managedPerson);
    populatePersonDetails(person, managedPerson);
    managedPerson = personDao.find(managedPerson.getId());
    PostedPerson postedPerson = new PostedPerson(managedPerson);
    return postedPerson;
}
Also used : Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson)

Example 3 with PostedPerson

use of gov.ca.cwds.rest.api.domain.PostedPerson 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)

Aggregations

Person (gov.ca.cwds.rest.api.domain.Person)3 PostedPerson (gov.ca.cwds.rest.api.domain.PostedPerson)3 PersonAddress (gov.ca.cwds.data.persistence.ns.PersonAddress)1 ApiException (gov.ca.cwds.rest.api.ApiException)1 Address (gov.ca.cwds.rest.api.domain.Address)1 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)1 HashSet (java.util.HashSet)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 Test (org.junit.Test)1