Search in sources :

Example 1 with Reporter

use of gov.ca.cwds.data.persistence.cms.Reporter in project API by ca-cwds.

the class ReporterService method update.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#update(java.io.Serializable,
   *      gov.ca.cwds.rest.api.Request)
   */
@Override
public gov.ca.cwds.rest.api.domain.cms.Reporter update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.Reporter;
    gov.ca.cwds.rest.api.domain.cms.Reporter reporter = (gov.ca.cwds.rest.api.domain.cms.Reporter) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        Reporter managed = new Reporter(reporter, lastUpdatedId);
        managed = reporterDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.Reporter(managed);
    } catch (EntityNotFoundException e) {
        LOGGER.info("Reporter not found : {}", reporter);
        throw new ServiceException(e);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.data.persistence.cms.Reporter) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 2 with Reporter

use of gov.ca.cwds.data.persistence.cms.Reporter in project API by ca-cwds.

the class ReporterService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public PostedReporter create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.Reporter;
    gov.ca.cwds.rest.api.domain.cms.Reporter reporter = (gov.ca.cwds.rest.api.domain.cms.Reporter) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        Reporter managed = new Reporter(reporter, lastUpdatedId);
        managed = reporterDao.create(managed);
        return new PostedReporter(managed);
    } catch (EntityExistsException e) {
        LOGGER.info("Reporter already exists : {}", reporter);
        throw new ServiceException(e);
    }
}
Also used : PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.data.persistence.cms.Reporter) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 3 with Reporter

use of gov.ca.cwds.data.persistence.cms.Reporter in project API by ca-cwds.

the class ReporterDaoIT method testUpdate.

@Override
@Test
public void testUpdate() throws Exception {
    Reporter reporter = new Reporter("AbiQCgu0Hj", "  ", "City", (short) 591, (short) 0, "N", null, " ", null, "N", "Fred", "Reporter", "N", 0, BigDecimal.valueOf(0), " ", " ", BigDecimal.valueOf(0L), 0, (short) 1828, "Street", "12345", " ", new Integer(95845), "AbiQCgu0Hk", (short) 0, "51");
    Reporter updated = reporterDao.update(reporter);
    assertThat(reporter, is(updated));
}
Also used : Reporter(gov.ca.cwds.data.persistence.cms.Reporter) Test(org.junit.Test)

Example 4 with Reporter

use of gov.ca.cwds.data.persistence.cms.Reporter in project API by ca-cwds.

the class ReporterDaoIT method testDeleteEntityNotFoundException.

@Override
@Test
public void testDeleteEntityNotFoundException() throws Exception {
    String id = "ZZZZZZZ999";
    Reporter deleted = reporterDao.delete(id);
    assertThat(deleted, is(nullValue()));
}
Also used : Reporter(gov.ca.cwds.data.persistence.cms.Reporter) Test(org.junit.Test)

Example 5 with Reporter

use of gov.ca.cwds.data.persistence.cms.Reporter in project API by ca-cwds.

the class ReporterDaoIT method testFindAllReturnsCorrectList.

@Override
@Test
public void testFindAllReturnsCorrectList() throws Exception {
    Query query = session.getNamedQuery("gov.ca.cwds.data.persistence.cms.Reporter.findAll");
    @SuppressWarnings("unchecked") final List<Reporter> list = query.list();
    System.out.println("size of query list is: " + list.size());
    for (Reporter c : list) {
        System.out.println("id " + c.getPrimaryKey() + " " + c.getLastName());
    }
    assertThat(query.list().size(), is(0));
}
Also used : Query(org.hibernate.Query) Reporter(gov.ca.cwds.data.persistence.cms.Reporter) Test(org.junit.Test)

Aggregations

Reporter (gov.ca.cwds.data.persistence.cms.Reporter)11 Test (org.junit.Test)9 PostedReporter (gov.ca.cwds.rest.api.domain.cms.PostedReporter)2 ServiceException (gov.ca.cwds.rest.services.ServiceException)2 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 Query (org.hibernate.Query)1