Search in sources :

Example 1 with Allegation

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

the class AllegationService method create.

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

Example 2 with Allegation

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

the class AllegationDaoIT method testDeleteEntityNotFoundException.

@Override
@Test
public void testDeleteEntityNotFoundException() throws Exception {
    Allegation deleted = allegationDao.delete("9999999ZZZ");
    assertThat(deleted, is(nullValue()));
}
Also used : Allegation(gov.ca.cwds.data.persistence.cms.Allegation) Test(org.junit.Test)

Example 3 with Allegation

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

the class AllegationDaoIT method testUpdateEntityNotFoundException.

@Override
@Test
public void testUpdateEntityNotFoundException() throws Exception {
    thrown.expect(EntityNotFoundException.class);
    gov.ca.cwds.rest.api.domain.cms.Allegation vda = validDomainAllegation();
    Allegation allegation = new Allegation("1234567ABC", DomainChef.uncookDateString(vda.getAbuseEndDate()), DomainChef.uncookDateString(vda.getAbuseStartDate()), vda.getAbuseFrequency(), vda.getAbuseFrequencyPeriodCode(), vda.getAbuseLocationDescription(), vda.getAllegationDispositionType(), vda.getAllegationType(), vda.getDispositionDescription(), DomainChef.uncookDateString(vda.getDispositionDate()), DomainChef.cookBoolean(vda.getInjuryHarmDetailIndicator()), vda.getNonProtectingParentCode(), DomainChef.cookBoolean(vda.getStaffPersonAddedIndicator()), vda.getVictimClientId(), vda.getPerpetratorClientId(), vda.getReferralId(), vda.getCountySpecificCode(), DomainChef.cookBoolean(vda.getZippyCreatedIndicator()), vda.getPlacementFacilityType(), null, null);
    allegationDao.update(allegation);
}
Also used : Allegation(gov.ca.cwds.data.persistence.cms.Allegation) Test(org.junit.Test)

Example 4 with Allegation

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

the class AllegationDaoIT method testFindEntityNotFoundException.

@Override
@Test
public void testFindEntityNotFoundException() throws Exception {
    Allegation found = allegationDao.find("9999999ZZZ");
    assertThat(found, is(nullValue()));
}
Also used : Allegation(gov.ca.cwds.data.persistence.cms.Allegation) Test(org.junit.Test)

Example 5 with Allegation

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

the class AllegationService 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.Allegation update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.Allegation;
    gov.ca.cwds.rest.api.domain.cms.Allegation allegation = (gov.ca.cwds.rest.api.domain.cms.Allegation) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        Allegation managed = new Allegation((String) primaryKey, allegation, lastUpdatedId);
        managed = allegationDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.Allegation(managed);
    } catch (EntityNotFoundException e) {
        LOGGER.info("Allegation not found : {}", allegation);
        throw new ServiceException(e);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Allegation(gov.ca.cwds.data.persistence.cms.Allegation) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Aggregations

Allegation (gov.ca.cwds.data.persistence.cms.Allegation)10 Test (org.junit.Test)8 PostedAllegation (gov.ca.cwds.rest.api.domain.cms.PostedAllegation)2 ServiceException (gov.ca.cwds.rest.services.ServiceException)2 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1