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;
}
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;
}
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()));
}
Aggregations